<template>
  <div class="article_share_v">
    <div class="head_bar">
      <div class="left icon_div">
        <img class="left icon" src="https://c2.gogoh5.com/gsf/se/ncp/144.jpg">
        <div class="left head_name">XXXX</div>
      </div>
      <div class="right rmar_div">
        <div class="gradation_red_btn open_btn" @click="$common.downloadApp()">打开</div>
      </div>
    </div>
    <v-Content v-if="hasContent && article" v-bind:articleInfo="article"></v-Content>
    <div v-else-if="!hasContent" class="isEmpty_div">
      <div class="msg_title">页面不见了！</div>
      <div class="msg_content">您要找的文章出现了问题，或者已被删除了！</div>
      <div class="gradation_red_btn dl_btn emt" @click="$common.downloadApp()">打开“XXXXAPP”查看更多</div>
    </div>
    <div v-else>
      <img src="static/img/loader.gif" class="load_gif">
    </div>
  </div>
</template>
<script>
  import Content from "./share/Content";
  export default {
    name: 'ArticleShare',
    components: {'v-Content': Content},
    data() {
      return {
        hasContent: true,
        article: undefined // 文章信息
      }
    },
    created() {
      let articleId = this.$route.query.articleId;
      let uid = this.$route.query.uid;
      this.getArticleShare(articleId, uid);
    },
    mounted() {
      document.title = "XXXX_热点文章";
    },
    methods: {
      // 分享文章内容接口
      getArticleShare(articleId, uid) {
        var self = this;
        if (articleId && uid) {
          let url = this.urls.articleShare + "?articleId=" + articleId + "&uid=" + uid;

          this.$http.get(url).then(function (response) {
            let status = response.data.status;
            let data = response.data.data;
            if (response.data && status === 0 && data && data.article) {
              document.title = "XXXX_热点文章_" + data.article.title;
              self.hasContent = true;
              self.article = data;
            } else { // 没有返回参数
              self.isEmpty("");
            }
          }).catch(function (error) {
            console.error(error);
            self.isEmpty("");
          });
        } else { // 没有传递参数
          self.isEmpty("文章链接异常");
        }
      },
      // 没有内容的显示规则
      isEmpty(msg) {
        console.log("msg=" + msg);
        this.hasContent = false;
      },
      // 计算发文时间
      getDateDifference(timestamp) {
        let nowTimestamp = new Date().getTime();
        if (nowTimestamp >= timestamp) {
          let result = "";
          let timediff = nowTimestamp - timestamp;
          let days = parseInt(timediff / 86400000); //计算天数
          result = days + "天前";
          if (days >= 30) {
            let months = parseInt(days / 30);
            result = months + "月前";
          } else if (days == 0) {
            let hours = parseInt(timediff / 3600000); //计算小时数
            result = hours + "小时前";
            if (hours == 0) {
              let mins = parseInt(timediff / 60000); //计算分钟数
              result = mins + "分钟前";
            }
          }
          return result;
        } else {
          return "";
        }
      }
    }
  }
</script>
